package com.edu.javaproect.service;

import com.alibaba.fastjson.JSONObject;
import com.edu.javaproect.Constants;
import com.edu.javaproect.bean.HotVideo;
import com.edu.javaproect.bean.HotVideoCommon;
import com.edu.javaproect.request.HttpUtils;

import java.util.List;

/**
 * @author:秇稔
 * @email:2580108178@qq.com
 * @Date:2021/12/8 22:15
 * @desc：
 **/
public class HotVideoService {
    /***
     * 该方法用于获取热门数据，并将热门数据返回
     * @return
     */
    public List<HotVideo> getHotVideo(){
        String url = Constants.TRIP_URL
                +"?key="+Constants.TRIP_KEY
                +"&type=travel_new"
                +"&size=20";
        String result = HttpUtils.get(url);
        //System.out.println(result);
        //json解析
        HotVideoCommon videoCommon = JSONObject.parseObject(result, HotVideoCommon.class);
//        System.out.println(videoCommon.reason);
//        System.out.println(videoCommon.error_code);
//        System.out.println(videoCommon.result.size());
        return videoCommon.result;
    }
    public List<HotVideo> LastHotVideo(){
        String url = Constants.TRIP_URL
                +"?key="+Constants.TRIP_KEY
                +"&type=food_overall"
                +"&size=20";
        String result = HttpUtils.get(url);
        //json解析
        HotVideoCommon videoCommon = JSONObject.parseObject(result, HotVideoCommon.class);
        return videoCommon.result;
    }
}
